<!--头部公共部分-->
{include file="common/header" /}
<div style="padding:15px;" id="returnfunf_money">
    <form class="layui-form layui-form-pane">

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="font-size: 10px;">到款(数量/金额)</label>
                <label class="layui-form-label"  id="already_allocated" style="font-size: 10px;"><font  color="#46A3FF">已分配</font></label>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="font-size: 10px;">剩余金额</label>
                <label class="layui-form-label" id="surplus" style="font-size: 10px;"><font  color="#46A3FF">剩余</font></label>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="font-size: 10px;">回抽金额</label>
            <div class="layui-input-inline">
                <input type="number"  min="0" max="{$project_surplus_amount}" style="font-size: 10px;" oninput="Set_Project_nums(this)"  name="money_" id="money" placeholder="回抽金额" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="font-size: 10px;">回抽数量</label>
            <div class="layui-input-inline">
                <input type="number" style="font-size: 10px;"  name="num_" id="num" autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input class="layui-btn" lay-submit lay-filter="form" value="确定" readonly>
            </div>
        </div>
    </form>
</div>
<!--底部公共部分-->
{include file="common/footer" /}

<script>
    var unit_price = '{$unit_price}';   //单价
    var project_id = '{$project_id}';   //项目id
    var project_type = '{$project_type}';   //项目类型
    var contract_number = '{$contract_number}'; //订单编号
    var campus_id = '{$campus_id}'; //  分配校区id

    var num = 0.00;
    /*
    $('#returnfunf_money').click(function () {
        var money =   $('#money').val();
        num = (money / unit_price).toFixed(5);
        $('#num').val(num);

    })
    */

    function Set_Project_nums(obj) {
        var money =   $('#money').val();
        num = (money / unit_price).toFixed(5);
        $('#num').val(num);

    }


    layui.use(['table', 'laydate','element', 'jquery','form','layer'], function(){
        var $ = layui.jquery
            ,element = layui.element
            ,layer = layui.layer
            ,form = layui.form;

        var table = layui.table,
            laydate = layui.laydate,
            $ = layui.$;

        //监听提交
        form.on('submit(form)', function (data) {
            var field = data.field;
            console.log(field.num_);
            if(field.num_ <= 0){
                layer.msg("请输入回抽资金数值");
                return;
            }
            var isLoad;
            $.ajax({
                url: '{:url("contract/returnfund")}?project_id='+ project_id  + '&project_type=' + project_type + '&contract_number='+ contract_number + '&campus_id='+ campus_id,
                method: "post",
                data: field,
                beforeSend: function () {
                    isLoad = layer.load(0, {
                        shade: false
                    }); //0代表加载的风格，支持0-2
                },
                success: function (result) {
                    layer.msg(result.msg);
                    if (result.code === 1) {
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            parent.location.reload();
                        }, 2000);
                    }
                },
                complete: function () {
                    layer.close(isLoad)
                },
                error: function (error) {
                    console.log(error)
                }
            });
            return false;
        });
    });

</script>